﻿using Furion.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using todo.EntityFramework.Entities;
using todo.EntityFramework.FromBody;
using todo.EntityFramework.ViewModels.UI;
using todo.books.IServices;
using todo.IRepository;
using todo.bases.Services;
using Microsoft.Extensions.Logging;

namespace todo.books.Services
{
   public class DoBooksServices : BaseServices<DoBooks>, IDoBooksServices, ITransient
    {
        private readonly IDoBooksRepository _dal;
        private readonly IUnitOfWork _unitOfWork;
        private readonly ILogger<DoBooksServices> _logger;
        public DoBooksServices(IDoBooksRepository dal,
                                IUnitOfWork unitOfWork,
                                 ILogger<DoBooksServices> logger)
        {
            this._dal = dal;
            base.BaseDal = dal;
            _unitOfWork = unitOfWork;
            _logger = logger;
        }

        public async Task<AdminUiCallBack> AddBooks(FMBooksInsertModel entity)
        {
            DoBooks books = new DoBooks();
            books.Name = "测试书籍";
            return await _dal.InsertAsync(books);
        }

        public Task<AdminUiCallBack> DeleteBooksByIdsAsync(int[] ids)
        {
            throw new NotImplementedException();
        }

        public Task<AdminUiCallBack> UpdateBooksAsync(FMBooksInsertModel entity)
        {
            throw new NotImplementedException();
        }

        public async Task<bool> IsUserExBooksAsync(FMBooksInsertModel entity)
        {
            _logger.LogInformation("[Begin] DoBooksServices Query User data for");
            var IsUser = await _dal.ExistsAsync(it=>it.UserId==entity.UserId);
            _logger.LogInformation("[End] DoBooksServices Query User data for");
            return IsUser;
        }
    }
}
